package fr.castorhoz.isi_connectivity_widget.roaming_widget;

import java.util.ArrayList;
import java.util.List;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import fr.castorhoz.isi_connectivity_widget.ConnBroadcastReceiver;
import fr.castorhoz.isi_connectivity_widget.ConnButton;
import fr.castorhoz.isi_connectivity_widget.database.DBAdapter;

/**
 * @author HozakaN
 *
 */
public class RoamingBroadcastReceiver extends ConnBroadcastReceiver {
	
	private static List<Integer> appWidgetIds = new ArrayList<Integer>();
	
	private DBAdapter dbAdapter;
	
	public RoamingBroadcastReceiver(Context context) {
		super(context);
		dbAdapter = new DBAdapter(context);
		dbAdapter.open();
		appWidgetIds = dbAdapter.getAppWidgetIdUsingWidget(ConnButton.widgets.gpsWidget.name());
		dbAdapter.close();
	}
	
	/**
	 * Adds the appWidget to the ones that need to be notified when the broadcast receiver receives an event
	 * @param appWidgetId
	 */
	public static void addAppWidget(int appWidgetId) {
		Log.d(RoamingBroadcastReceiver.class.getName(), "adding appWidgetId "+appWidgetId+" to RoamingBroadcastReceiver");
		appWidgetIds.add(appWidgetId);
	}

	@Override
	public void doOnReceive(Context context, Intent intent) {
		final String action = intent.getAction();

		Log.i(this.getClass().toString(), "intent roaming : " + action);
				
	}

	@Override
	protected List<Integer> getAppWidgetIds() {
		return appWidgetIds;
	}

//	@Override
//	protected void registerItself(Context context) {
//		/*IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
//		context.getApplicationContext().registerReceiver(this, filter);
//		Log.d(this.getClass().getName(), "broadcast receiver "+this.getClass().getCanonicalName()+" has registered itself");*/
//	}

	@Override
	public String getBroadcastAction() {
		return BluetoothAdapter.ACTION_STATE_CHANGED;
	}

	@Override
	protected String getWidgetName() {
		return ConnButton.widgets.roamingWidget.name();
	}
	
	

}
